package com.bwie.user.controller;

import com.alibaba.fastjson.JSONObject;
import com.bwie.common.domain.request.UserRequest;
import com.bwie.common.result.Result;
import com.bwie.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private HttpServletRequest request;

    @PostMapping("/findByPhone")
    public Result findByPhone(@RequestParam String phone){
        log.info("功能名称:手机号查询,请求URI:{},请求方式:{},请求参数:{}",
                request.getRequestURI(),
                request.getMethod(),
                phone);
        Result byPhone = userService.findByPhone(phone);
        log.info("功能名称:手机号查询,请求URI:{},请求方式:{},响应结果:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(byPhone));
        return byPhone;
    }

    @PostMapping("/regist")
    public Result regist(@RequestBody UserRequest userRequest){
        log.info("功能名称:注册,请求URI:{},请求方式:{},请求参数:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(userRequest));
        Result regist = userService.regist(userRequest);
        log.info("功能名称:注册,请求URI:{},请求方式:{},响应结果:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(regist));
        return regist;
    }



}
